
from sqlalchemy import Column, Integer, String, Float, DateTime, UniqueConstraint, ForeignKey

from QualityInspectionViolation.DbInit.mysqlDb import Base


class Department(Base):
    __tablename__ = 'department'
    id = Column(Integer, primary_key=True)
    name = Column(String(32))
    organId = Column(String(255))
    createdAt = Column(DateTime)
    updatedAt = Column(DateTime)

    def queryDepartment(self, organId, organLen, pageSize, pageNo, session):
        department = session.execute('select * from department where organId like :organId and length(organId) = :organLen limit :pageLimit offset :pageOffset',
                        params={"organId": organId + "%", "organLen": organLen, "pageLimit": pageSize,"pageOffset": (pageNo - 1) * pageSize}).fetchall()
        return department